<template>
  <div class="app">
    <router-view />
  </div>
</template>

<script setup>
import { useWebSocketStore } from '@/store/websocket'
import { onMounted, onUnmounted } from 'vue'
import {useStore} from "vuex";

const wsStore = useWebSocketStore()
const strategyStore = useStore()
onMounted(async () => {
  // 从路由或任何地方获取参数
  const params = new URLSearchParams(window.location.search);
  const envParamId = params.get("env_param_id");
  const store = useStore()
  const simulationResultTotalId = params.get("simulation_id");
  const isHistory = params.get("isHistory")
  console.log("isHistory", isHistory)
  strategyStore.commit('SET_ENV_PARAM_ID', envParamId)
  await wsStore.getTotalEnergyAndActualLoad()
  if (isHistory === false || isHistory === 'false') {
    wsStore.connectWebSocket(envParamId, simulationResultTotalId)
    console.log("进行仿真------------------------------------")
  }
  else {
    store.commit('SET_STRATEGY_LOADING', { value: 'simple', isLoading: false })
    store.commit('SET_STRATEGY_LOADING', { value: 'dqn', isLoading: false })
    store.commit('SET_STRATEGY_LOADING', { value: 'a2c', isLoading: false })
    store.commit('SET_STRATEGY_LOADING', { value: 'ppo', isLoading: false })
    wsStore.historyData(simulationResultTotalId)
    console.log("查看历史数据------------------------------------")
  }
})

onUnmounted(() => {
  wsStore.closeWebSocket()
})
</script>

<style lang="scss" scoped>
.app {
  width: 100vw;
  height: 100vh;
  background-color: #020308;
  overflow: hidden;
}
</style>
